package org.zjx.command.basic;

import lombok.Getter;
import org.zjx.command.Command;
import org.zjx.core.GameWindow;
import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * 截图指令
 */
@Getter
public class ScreenshotCommand extends Command {
    private Image screenshot;

    public ScreenshotCommand(GameWindow window) {
        super(window, false, "Screenshot");
    }

    @Override
    protected void doExecute() {
        try {
            Rectangle bounds = targetWindow.getBounds();
            if (bounds != null && bounds.width > 0 && bounds.height > 0) {
                Robot robot = new Robot();
                screenshot = robot.createScreenCapture(bounds);
            }
        } catch (Exception e) {
            System.err.println("[Screenshot] Failed to capture: " + e.getMessage());
            screenshot = null;
        }
    }

    public BufferedImage getBufferedScreenshot() {
        return (screenshot instanceof BufferedImage) ? (BufferedImage) screenshot : null;
    }
}